package com.tanjie.blackbean.mybatis;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.tanjie.blackbean.mybatis.support.CustomPaginationInnerInterceptor;
import com.tanjie.blackbean.mybatis.support.AutoFieldFillHandler;
import com.tanjie.blackbean.mybatis.support.SqlLogInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author: tanjie
 * @date: 2022-04-14
 **/
@Slf4j
@Configuration
public class BlackBeanMybatisAutoConfiguration {

    @Bean
    public SqlLogInterceptor sqlLogInterceptor() {
        log.info("加载---sql日志格式化---");
        return new SqlLogInterceptor();
    }

    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        log.info("加载---Mybatis分页插件---");
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new CustomPaginationInnerInterceptor(DbType.MYSQL));
        return interceptor;
    }

    @Bean
    public AutoFieldFillHandler mybatisAutoFieldFillHandler() {
        log.info("加载---Mybatis字段自动填充功能---");
        return new AutoFieldFillHandler();
    }

}
